package thread;

class Counters{
    public static int count = 0;

    synchronized public static void add(){
        count++;
    }
    public int getCount(){
        return count;
    }
}
public class Demo22 {

    public static void main(String[] args) throws InterruptedException {
        Counters counters = new Counters();
        Counters counters1 = new Counters();
        Thread t1 = new Thread(()->{
            for (int i = 0; i < 100000; i++) {
                counters.add();
            }
        });
        Thread t2 = new Thread(()->{
            for (int i = 0; i < 100000; i++) {
                counters1.add();
            }
        });
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println(counters.getCount());
    }
}
